package com.sgb.businessmodule.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.harisucici.jetpackbase.base.HBaseViewModel;
import com.sgb.businessmodule.BusinessConfig;
import com.sgb.businessmodule.entity.BusinessRequestEntity;
import com.sgb.businessmodule.entity.HomeBusinessListEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;

import java.util.List;

public class HomeBusinessChildModel extends HBaseViewModel {

    //首页列表数据
    public MutableLiveData<List<HomeBusinessListEntity>> homeBusinessList = new MutableLiveData();
    //是否最后分页
    public boolean isLastPage;

    public HomeBusinessChildModel(@NonNull Application application) {
        super(application);
    }

    /*
     * 获取商机首页列表数据
     * */
    public void requestBusinessListData(BusinessRequestEntity entity) {
        BusinessConfig.getInstance().getApi().getHomeBusinessData(entity).enqueue(new ICallBack<BaseEntity<ListResponse<List<HomeBusinessListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<HomeBusinessListEntity>>> data) {
                if (data.getData().getList() != null) {
                    isLastPage = data.getData().getCurrentPage() >= data.getData().getTotal();
                    homeBusinessList.postValue(data.getData().getList());
                }
            }
        });
    }

}
